package bravo.xc.com.xc_bravo_android.base;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import butterknife.Unbinder;

/**
 * CREATED BY YANK
 * DATE : 2017/10/22
 * MAIL : YANK.TENYOND@GMAIL.COM
 * FUNCTION :
 */

public abstract class BaseActivity extends AppCompatActivity {

    protected Context context;
    protected Unbinder unbinder;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = this;
        if(getContentViewId()!=0){
            setContentView(getContentViewId());
            BindView();
        }
        init();
    }


    /******************* Method for child class*******************/

    /**Bind View**/
    protected abstract void initView();
    /**Set Default Data**/
    protected abstract void initData();
    /**Get View of Child Content**/
    protected abstract int getContentViewId();
    /**Bind ButterKnife**/
    protected abstract Unbinder getBinder();
    /**on Presenter Destroy**/
    protected abstract void onChildDestroy();


    /****************** Common Method for child*****************/

    /**Get Binder**/
    private void BindView(){
        unbinder = getBinder();
    }
    /**Init Something**/
    protected void init(){
        initView();
        initData();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        onChildDestroy();
        if(unbinder!=null){
            unbinder.unbind();
        }
    }

}
